package com.example.client_fmf;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class Connection3 {

	String host ;
	int port ; 
	public Connection3(String host , int port)
	{
		this.host = host ;  
		this.port =  port ; 
	
	}
	 Socket socket = null;
	 DataOutputStream dataOutputStream = null;
	 DataInputStream dataInputStream = null;
	 
	 public void Send(String msg) throws IOException{
		 dataOutputStream.writeUTF(msg);
	 } 
	 public void connect() throws IOException
	 {
		 try {
		  socket = new Socket(host, port);
//		  socket.connect(new remoteAddr()));
//		  connect(new InetSocketAddress(host, port));
		  dataOutputStream = new DataOutputStream(socket.getOutputStream());
		  dataInputStream = new DataInputStream(socket.getInputStream());
		 }
		 catch (UnknownHostException e)
		 {
			  // TODO Auto-generated catch block
			  e.printStackTrace();
		  } 
		 catch (Exception e) 
		 {
			  // TODO Auto-generated catch block
			  e.printStackTrace();
			  
		 }
		 
		 finally
		 {
			  if (socket != null){
			   try {
			    socket.close();
			   } catch (IOException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			   }
			  }

			  if (dataOutputStream != null){
			   try {
			    dataOutputStream.close();
			   } catch (IOException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
			   }
			  }

			  if (dataInputStream != null){
			   try 
			   {
				   dataInputStream.close();
			   } 
			   catch (IOException e) 
			   {
				    // TODO Auto-generated catch block
				    e.printStackTrace();
			   }
			  }
		}
}
}
//	 catch (IOException e) 
//	 {
//		  // TODO Auto-generated catch block
//		  e.printStackTrace();
//	 }
//	finally
//	{
//		  if (socket != null){
//		   try {
//		    socket.close();
//		   } catch (IOException e) {
//		    // TODO Auto-generated catch block
//		    e.printStackTrace();
//		   }
//		  }
//
//		  if (dataOutputStream != null){
//		   try {
//		    dataOutputStream.close();
//		   } catch (IOException e) {
//		    // TODO Auto-generated catch block
//		    e.printStackTrace();
//		   }
//		  }
//
//		  if (dataInputStream != null){
//		   try {
//		    dataInputStream.close();
//		   } catch (IOException e) {
//		    // TODO Auto-generated catch block
//		    e.printStackTrace();
//		   }
//		  }
//		  
//		 }
	 

